package com.zyw.controller.order;

import com.zyw.entity.*;
import com.zyw.from.OrderFrom;
import com.zyw.service.clothing.ClothingService;
import com.zyw.service.order.OrderClientService;
import com.zyw.service.order.OrderService;
import com.zyw.service.personnel.PersonnelStaffService;
import com.zyw.service.procurement.ProcurementMaterialAnalysisService;
import com.zyw.service.repertory.RepertoryMaterialService;
import com.zyw.util.ResultVOUtil;
import com.zyw.vo.LayUITableVO;
import com.zyw.vo.ResultVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@Slf4j
@RequestMapping("/order/order")
public class OrderController {


    @Autowired
    public OrderService orderService;

    @Autowired
    public ClothingService clothingService;

    @Autowired
    public OrderClientService orderClientService;



    //菜品类别展示
    @GetMapping("/index")
    public String index(Model model){


        return "order/order/index";

    }

    //获取菜品类别信息
    @GetMapping("/list")
    @ResponseBody
    public LayUITableVO<List<Order>> list (@RequestParam(defaultValue = "1") Integer page,
                                           @RequestParam(defaultValue = "10") Integer limit,
                                           OrderFrom from){

        Map<String ,Object> map = new HashMap<>();
        map.put("page",page);
        map.put("limit",limit);
        map.put("from",from);
        LayUITableVO< List<Order>> vo = orderService.findPage(map);


        return vo;
    }

    //修改菜品类别信息1（查询指定id菜品分类详情）
    @GetMapping("/edit-ui")
    public String editUI(String id,Model model){

         Order order = orderService.selectById(id);
         List<Clothing> clothingList = clothingService.findAllIdAndName();
       List<OrderClient> orderClientList = orderClientService.findAllIdAndName();

        model.addAttribute("order",order);
        model.addAttribute("clothingList",clothingList);
        model.addAttribute("orderClientList",orderClientList);


        return "order/order/edit";

    }

    //执行修改
    @PostMapping("/edit")
    @ResponseBody
    public ResultVO edit(Order order){

        orderService.update(order);

        return ResultVOUtil.ok();
    }

    //修改菜品类别信息1（查询指定id菜品分类详情）
    @GetMapping("/add-ui")
    public String addUI(Model model){

        List<Clothing> clothingList = clothingService.findAllIdAndName();
        List<OrderClient> orderClientList = orderClientService.findAllIdAndName();


        model.addAttribute("clothingList",clothingList);
        model.addAttribute("orderClientList",orderClientList);

        return "order/order/add";

    }

    //执行修改
    @PostMapping("/add")
    @ResponseBody
    public ResultVO add(Order order){

        orderService.save(order);

        return ResultVOUtil.ok();
    }
    //执行删除
    @PostMapping("/del")
    @ResponseBody
    public ResultVO del(String id){
        orderService.delelteById(id);
        return ResultVOUtil.ok();
    }

}
